export default {
  data () {
    return {
      isLoading: false,
      // 查询商品列表参数 ----------------
      pagenum: 1,
      pagesize: 10,
      total: 0,
      // curChangeNum: 1,
      // 查询商品列表数据 ----------------
      goodsList: []

    }
  },
  methods: {
    /**
     * 获取商品列表
     * @param {number} pagenum 页码
     * @param {number} pagesize 一页的条数
     */
    async getGoodsList (pagenum = 1, pagesize = 10) {
      this.isLoading = true
      const res = await this.axios.get('goods', {
        params: {
          query: '',
          pagenum,
          pagesize
        }
      })
      this.isLoading = false
      try {
        const { data: { data: { pagenum: curChangeNum, goods, total }, meta: { status } } } = res
        if (status === 200) {
          this.goodsList = goods
          this.total = total
          console.log(res)
          this.pagenum = +curChangeNum
        }
      } catch (e) {}
    },
    /**
     * 点击分页页码
     * @param {number} curPage 当前页码
     */
    curChange (curPage) {
      console.log('fachu')
      this.$router.push(`/goods/${curPage}`)
      // this.pagenum = curPage
      // this.getGoodsList(curPage)
    },
    indexMethod (index) {
      return index + 1 + (this.pagenum - 1) * this.pagesize
    }
  },
  watch: {
    $route (to, from) {
      const params = +to.params.id || 1
      this.getGoodsList(params)
    }
  },
  created () {
    console.log('数据')
    const params = +this.$route.params.id || 1
    this.getGoodsList(params)
  }
}
